//
//  BVSelectCityViewController.m
//  BuyVegetable
//
//  Created by yushanchang on 16/11/17.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVSelectCityViewController.h"
#import "BVChangeCityLocationCell.h"

#define CHANGECITYCELL_IDENTIFIER @"BVChangeCityLocationCell"

@interface BVSelectCityViewController ()
<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation BVSelectCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.selectArea.names;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.city.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    BVChangeCityLocationCell *city_cell = [tableView dequeueReusableCellWithIdentifier:CHANGECITYCELL_IDENTIFIER];
    if (!city_cell) {
        city_cell = [[NSBundle mainBundle] loadNibNamed:CHANGECITYCELL_IDENTIFIER owner:self options:nil][1];
    }
    city_cell.sectionThreeLabel.text = [self.city[indexPath.row] names];
    return city_cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    BVChangeCityLocationCell *city_cell = [tableView cellForRowAtIndexPath:indexPath];
    BVSelectArea *select_area = self.city[indexPath.row];
    [self.user setCity:select_area.names city_id:select_area.ID];
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
